//
//  FarmDrugListCell.m
//  YK_BaseMediator
//
//  Created by edward on 2021/3/12.
//  Copyright © 2021 Edward. All rights reserved.
//

#import "FarmDrugListCell.h"
#import "YKFarmViewModel.h"
#import <Masonry/Masonry.h>
#import <YK_ExectionModel/YKNSObjectCore.h>
#import <YK_ExectionModel/YKUIKitCore.h>

@interface FarmDrugListCell ()

///
@property(nonatomic,strong) UILabel *drugNameLabel;
///
@property(nonatomic,strong) UILabel *drugMuchLabel;
///
@property(nonatomic,strong) UILabel *createTimeLabel;
///
@property(nonatomic,strong) UILabel *MealTimeLabel;
@end

@implementation FarmDrugListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    [self.contentView addSubview:self.drugNameLabel];
    [self.contentView addSubview:self.drugMuchLabel];
    [self.contentView addSubview:self.MealTimeLabel];
    [self.contentView addSubview:self.createTimeLabel];
    [self.drugNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.height.mas_equalTo(24);
        make.width.mas_equalTo((YKScreenW - 20)/2);
    }];
    [self.drugMuchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.drugNameLabel.mas_top);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
        make.height.width.mas_equalTo(self.drugNameLabel);
    }];
    [self.MealTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.drugNameLabel.mas_bottom).offset(10);
        make.left.width.mas_equalTo(self.drugNameLabel);
        make.height.mas_equalTo(24);
    }];
    [self.createTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.MealTimeLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(24);
        make.bottom.mas_equalTo(-20).priorityHigh();
    }];
}

- (void)configDataWithViewModel:(YKFarmViewModel *)viewModel indexPath:(NSIndexPath *)indexPath dataSource:(NSArray *)dataSource
{
    @weakify(self);
    [viewModel getDrugDetail:indexPath block:^(NSString * _Nonnull drugname, NSString * _Nonnull much, NSString * _Nonnull MealTime, NSString * _Nonnull createTime, NSString * _Nonnull drugId) {
        @strongify(self);
        self.drugNameLabel.text = drugname;
        self.drugMuchLabel.text = much;
        self.MealTimeLabel.text = MealTime;
        self.createTimeLabel.text = createTime;
    }];
}

- (UILabel *)drugNameLabel
{
    if(!_drugNameLabel)
    {
        _drugNameLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _drugNameLabel.textColor = UIColor.labelColor;
        } else {
            
            _drugNameLabel.textColor = UIColor.blackColor;
        }
        _drugNameLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _drugNameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _drugNameLabel;
}

- (UILabel *)drugMuchLabel
{
    if(!_drugMuchLabel)
    {
        _drugMuchLabel = [[UILabel alloc]init];
        _drugMuchLabel.textColor = UIColor.redColor;
        _drugMuchLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _drugMuchLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _drugMuchLabel;
}
- (UILabel *)createTimeLabel
{
    if(!_createTimeLabel)
    {
        _createTimeLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _createTimeLabel.textColor = UIColor.labelColor;
        } else {
            
            _createTimeLabel.textColor = UIColor.blackColor;
        }
        _createTimeLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _createTimeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _createTimeLabel;
}

- (UILabel *)MealTimeLabel
{
    if (!_MealTimeLabel) {
        _MealTimeLabel = [[UILabel alloc] init];
        if (@available(iOS 13.0, *)) {
            _MealTimeLabel.textColor = UIColor.labelColor;
        } else {
            
            _MealTimeLabel.textColor = UIColor.blackColor;
        }
        _MealTimeLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
        _MealTimeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _MealTimeLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
